package com.study.bootstudy.controller;

//import com.demo.starter.controller.DemoController;
//import com.demo.starter.service.DemoService;
import com.study.bootstudy.entity.Person;
//import com.study.bootstudy.listener.MySessionLinstener;
import com.study.bootstudy.serviice.ApiService;
import com.study.bootstudy.util.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * @Author RenPu
 * @Date 2021/7/30 15:52
 * @Version 1.0
 * @Description:
 **/

@RestController
public class MyController <T> {

//    @Autowired
//    private DemoService demoService;

    @Resource
    ApiService apiService;


//    @GetMapping("hello")
//    public String hello(HttpSession session){
//        //session.setAttribute("aa","aaa");
//        return "hello";
//    }

    @GetMapping("hello")
    public String hello(Model mode) {
        mode.addAttribute("msg", "hello---thymeleaf");
        return "hello";
    }

//
//    @GetMapping("/online")
//    public String online() {
//        return "当前在线人数为" + MySessionLinstener.online + "人";
//    }
//

    @GetMapping("thymeleaf")
    public String thymeleaf(ModelMap mode, HttpSession session) {
        mode.put("thText", "th:text 设置文本内容 <b>加粗</b>");
        mode.put("thUText", "th:utext 设置文本内容 <b>加粗</b>");
        mode.put("thValue", "thValue 设置当前元素的value值");
        mode.put("thEach", "Arrays.asList(\"th:each\",\"遍历列表\")");
        mode.put("thif", "msg is not null");
        mode.put("thObject", new Person("zhangsan", 12, "男","1636789567","71134567895"));
        session.setAttribute("name", "wangwu");
        return "thymeleaf";
    }


    @GetMapping("/login")
    public String login(HttpServletRequest request,HttpSession httpSession) {
//        httpSession.setAttribute("username","admin");
        String langue = request.getParameter("language");
        return "login";
    }

//
//    @GetMapping("/sayHello")
//    @ResponseBody
//    public String sayHello() {
//        return demoService.say();
//    }


    /**
     * 使用自定义注解结合hutool实现数据脱敏展示
     * @return
     */
    @GetMapping("/testTUOMI")
    @ResponseBody
    public Object testTUOMI() {

        Person person = Person.builder().name("王中王").age(38).gender("中年小班")
                        .idNumber("311678900311").phone("17839026983").build();
        return person;
    }


    @RequestMapping("/apiMethond/{markId}")
    public ApiResult apiMethond(@PathVariable String markId){
       return apiService.cancelServiceCodeViewThree(Integer.valueOf(markId));
    }



}
